package com.Wlongtao.eBusiness.dao;


import com.Wlongtao.eBusiness.dto.PlayerProject;
import com.Wlongtao.eBusiness.entity.Player;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PlayerRepository extends CrudRepository<Player,Long> {
    @Override
    List<Player> findAll();

    @Query(nativeQuery = true,value = "SELECT s.name, s.wechat_id , COUNT(s.player_id) AS projectCount " +
            "FROM player AS s LEFT JOIN game_player AS ps ON s.player_id = ps.player_id " +
            "GROUP BY s.name, s.wechat_id ORDER BY 3 desc;")
    List<PlayerProject> playerProjects();
}
